var Course = { 
	item: null,
	num:{0:"一、",1:"二、",2:"三、",3:"四、",4:"五、",5:"六、",6:"七、"},
	practiceNum: 1,
	commentIndex: 0,
	myScroll: null,
	flag: true,
	courseIndexInit: function(category){ 
        var listFn = function(category){
        	if (CurrentUser){
				$ajax({
	                "url": "/user/detail?1",
	                "data": {
	                    _id: CurrentUser._id
	                },
	                success: function(res){
	                	SetLS("user",res.result);
	                    CurrentUser = res.result;
						list(category);
					}
				});
			} else 
				list(category);	
			function list(category){
				$ajax({
					url: "/direction/listCourse",
					data: {
		            	category: category,
		            	full: true
		           	},
					success: function(res) {
						var data = res.result;
						var course = "";
						for (var i = 0; i < data.length; i ++){
							var desc = data[i].desc.length>30?data[i].desc.substr(0,30) + "...":data[i].desc;
							desc = desc.replace(new RegExp("\n","gm"),"<br/>");

							var flag = false;
							var content = '';
							if (CurrentUser&&CurrentUser.course){
								for (var j = 0; j < CurrentUser.course.length; j ++){
									if (data[i]._id == CurrentUser.course[j]._id)
										flag = true;
								}
							}	
							if (flag)
								content = "<div class='ufp8 ub ub-ac c_gre'><span class='uba uc-a1 b_green upp3 ufp9'>已选</span></div>";

							course += "<div data-id='" + data[i]._id + "' class='ub ubb b_gra upp7' ontouchstart='zy_touch()' onclick='Course.jumpDetail(\"" + data[i]._id + "\",\"" + data[i].name + "\")'>" + 
										"	<div class='ub-img7 uw50 imgScale' style='background-image:url(" + Core.id2url(data[i]) + ")'></div>" + 
										"	<div class='ub ub-f1 ub-ver uml_p3'>" + 
										"		<div class='ub'>" + 
										"			<div class='ub-f1 upp5 ut-s'>" + data[i].name + "</div>" + 
										content + 
										"		</div>" + 
										"		<div class='ub ufp8'>" + 
										"			<div class='ub-f1 ub uptb_p5 ub-ac ub-pc'>" + 
										"				<div class='ub-img1 uw1p5 uh1p5 im_ico_hours'></div>" + 
										"				<div class='ub-f1'>&nbsp;课时 : " + data[i].classHour + "课时</div>" + 
										"			</div>" + 
										"		</div>" + 
										"		<div class='ufp8 upp5 t-gra line-hei1p5'>" + desc + "</div>" + 
										"	</div>" + 
										"</div>";
							//Res.gnCourse(Core.id2url(data[i]),data[i].name,(data[i].teachers[0]?data[i].teachers[0].name:"暂无讲师"),data[i].classHour,des,data[i]._id,Course.jumpDetail);			
						}
						if(course.length === 0)
	                       course = '<div class="ub-f1 ub ub-ver ub-ac ub-pc uw100 upt_percent30">' + 
									'	<div class="uc-a2 bc_green upp5 t-wh uw50 tx-c">该类型下暂无相应课程！</div>' + 
									'</div>';
						$("#courseList").html(course);
						$(".imgScale").height($(".imgScale").width()*7/10+"px");
					}
				});
			}
		}
		listFn(category);	
	},
	jumpDetail: function(id,name){ 
		SetLS("courseId",id);
		SetLS("courseName",name);
		var flag = false;
		if (CurrentUser){
			for (var i = 0; i < CurrentUser.course.length; i ++){
				if (id == CurrentUser.course[i]._id)
					flag = true;
			}
		}	
		if (flag)
			OpenNewWin("study_myCourse_detail");
		else
			OpenNewWin("index_course_detail");
	},
	myCourseProjectInit: function(){ 
		$ajax({
			url:"/user/getCourseProject",
			success: function(res) {
				var data = res.result;
				//我的项目列表
				var project = "";
				for (var i = 0; i < data.project.length; i ++){
					var desc = '';
					if (data.project[i].desc)
						desc = data.project[i].desc.length>42?data.project[i].desc.substr(0,42) + "...":data.project[i].desc;
					else
						desc = "暂无描述";
					project += 	'<div class="ub ubb b_gra upp7" ontouchstart="zy_touch()" onclick="Project.jumpDetail(\'' + data.project[i]._id + '\',\'' + data.project[i].name + '\')">' + 
								'	<div class="ub-img7 uw50 imgScale" >' +
								'      <img src="' + Core.id2url(data.project[i].picture?data.project[i].picture:"","photo") + '" style="width:100%;" />'+
								'   </div>' + 
								'	<div class="ub ub-f1 ub-ver uml_p3">' + 
								'		<div class="upp5 ut-s">' + data.project[i].name + '</div>' + 
								'		<div class="ub ufp8 upp5 ub-ac ub-pc">' + 
								'			<div class="ub-img1 uw1p5 uh1p5 im_ico_origin"></div>' + 
								'			<div class="ub-f1 ut-s">&nbsp;创建时间 : ' + (new Date(data.project[i].create)).pattern('yyyy-MM-dd') + '</div>' + 
								'		</div>' + 
								'		<div class="ufp8 upp5 t-gra line-hei1p5">' + desc + '</div>' + 
								'	</div>' + 
								'</div>';
					//Res.gnproject(Core.id2url(data[i]),data[i].name,data[i].organization);			
				}
				if(project.length == 0)
				   	project = 	'<div class="ub-f1 ub ub-ver ub-ac ub-pc uw100">' + 
								'	<div class="uc-a2 bc_green upp5 t-wh uw50 tx-c" ontouchstart="zy_touch()" onclick="Index.jump(\'tab0\',\'首页\');">您还没有参与任何项目,点我选项目吧！</div>' + 
								'</div>';
				$("#myProjectList").html(project);
				//我的课程列表
				var course = '';
				if (data.course.length){
					for (var i = data.course.length-1; i >= 0; i --){ 
						var desc = data.course[i].desc.length>30?data.course[i].desc.substr(0,30) + "...":data.course[i].desc;
						desc = desc.replace(new RegExp("\n","gm"),"<br/>");
						course += "<div data-id='" + data.course[i]._id + "' class='ub ubb b_gra upp7' ontouchstart='zy_touch()' onclick='Course.jumpMyDetail(\"" + data.course[i]._id + "\",\"" + data.course[i].name + "\")'>" + 
									"	<div class='ub-img7 uw50 imgScale' style='background-image:url(" + Core.id2url(data.course[i]) + ")'></div>" + 
									"	<div class='ub ub-f1 ub-ver uml_p3'>" + 
									"		<div class='upp5 ut-s'>" + data.course[i].name + "</div>" + 
									"		<div class='ub ufp8'>" + 
									"			<div class='ub-f1 ub uptb_p5 ub-ac ub-pc'>" + 
									"				<div class='ub-img1 uw1p5 uh1p5 im_ico_hours'></div>" + 
									"				<div class='ub-f1'>&nbsp;课时 : " + data.course[i].classHour + "课时</div>" + 
									"			</div>" + 
									"		</div>" + 
									"		<div class='ufp8 upp5 t-gra line-hei1p5'>" + desc + "</div>" + 
									"	</div>" + 
									"</div>";
					}
				} else { 
					course = 	'<div class="ub-f1 ub ub-ver ub-ac ub-pc uw100">' + 
								'	<div class="uc-a2 bc_green upp5 t-wh uw50 tx-c" ontouchstart="zy_touch()" onclick="Index.jump(\'tab0\',\'首页\');">您还没有报名任何课程,点我选课程吧！</div>' + 
								'</div>';
				}
				$("#myCourseList").html(course);	
				//$(".imgScale").height($(".imgScale").width()*7/10+"px");
				
				$(".imgScale").height($(".imgScale").width()*7/10+"px");
			}
		});
	},
	jumpAddMine: function(){

	},
	findMore: function(){ 
		SetLS("tab",{"url":"tab0","title":"首页"});
		PCall("father",'zy_con("content","tab0.html", 0, $("#header").outerHeight(), $("#footer").outerHeight())');
	},
	jumpMyDetail: function(id,name){ 
		SetLS("courseId",id);
		SetLS("courseName",name);
		OpenNewWin("study_myCourse_detail");
	},
	courseDetailInit: function(){ 
		var _id = GetLS("courseId");
		$ajax({
			url: "/course/detail",
			data: {
				_id: _id
			},
			success: function(res){ 
				var course = res.result;
				Course.item = course;
				SetLS("course",Course.item);
				SetLS("chapter",Course.item.chapter[0]);
				if (Course.item.chapter[0])
					SetLS("knowledge",Course.item.chapter[0].knowledge[0]);
				//课程介绍
				$("#courseName").text(course.name);
				$("#courseDes").text(course.desc);
				var teachers = '';
				for (var i = 0; i < course.teachers.length; i ++){ 
					course.teachers[i].category = Role.TUTOR
					var text = '';
					if (i == 0)
						text = '讲师&nbsp;:　';
					if(i-course.teachers.length+1 === 0)
					   teachers += '<div class="ub ub-f1 ubb b_gra uptb_1">';
					else
					   teachers += '<div class="ub ub-f1 b_gra uptb_1">';
					teachers += '	<div class="tx-r c_gra uwp25">' + text + '</div>' + 
								'	<div class="ub ub-f1">' + 
								'		<div class="uw3 uh3 ub-img1 uc-ap50" style="background-image:url(' + Core.id2url(course.teachers[i]) + ');"></div>' + 
								'		<div class="ub ub-ver ub-f1">	' + 
								'			<div class="c_base uh3 upl_p5">' + course.teachers[i].name + '</div>' + 
								'			<div class="c_tip upl_p5 line-hei1p7">' + course.teachers[i].desc + '</div>' + 
								'		</div>	' + 
								'	</div>' + 
								'</div>';
				}
				$("#des").append(teachers);
				//var  knowledge= course.chapter[0].knowledge[0];
				//视频区域
				$("#player").html('<img src="' + Core.id2url(course) + '" class="imgScale" style="width:100%;">');
					//$("#player").html('<img src="' + knowledge.first_image + '" style="width:100%;max-height: 13em;" ontouchstart="zy_touch()" onclick="Course.openVideo(\'' + knowledge.vid + '\');"><div class="im_play ub-img" style="position:absolute;height:40%;width:40%;top:30%;left:30%;" ontouchstart="zy_touch()" onclick="Course.openVideo(\'' + knowledge.vid + '\');"></div>');	
				$(".imgScale").height($(".imgScale").width()*9/16+"px");	
				//目录
				Course.guideInit(course);
			}
		});	
	},
	jumpSignup: function(id,vid){ 
		if (CurrentUser){
			var flag = false;
			for (var i = 0; i < CurrentUser.course.length; i ++){ 
				if (CurrentUser.course[i].id == id)
					flag = true;
			}
			if (flag)
				Course.openVideo(vid);
			else	
				return $alert("您尚未拥有此课程");
		} else {	
			$alert("需要登录，是否登录？",function(){ 
				OpenNewWin("signup");
			});
		}	
	},
	myCourseDetailInit: function(){ 
		var _id = GetLS("courseId");
		$ajax({
			url: "/course/detail",
			data: {
				_id: _id
			},
			success: function(res){ 
				var course = res.result;
				Course.item = course;
				SetLS("course",Course.item);
				SetLS("courseId",course._id);
				Course.courseFn(0,0,true);

				$("#guide").height(window.document.body.clientHeight-$("#player").height()-$("#tabTitle").height()-$("#tabSelect").height()-32);
			}
		});	
	},	
	courseFn: function(chapterNum,knowledgeNum,flag){ 
		Course.practiceNum = 1;
		$("#footer0").attr("onclick","Course.practiceSubmit('tip');").text("提交").removeClass("bg_gray").addClass("bc_green");
		PCall("study_myCourse_detail","$('#title').text('" + Course.item.name + " " + (Course.item.chapter[chapterNum]&&Course.item.chapter[chapterNum].knowledge[knowledgeNum]?Course.item.chapter[chapterNum].knowledge[knowledgeNum].name:'') + "')");
		// $("#footer0").attr("onclick","Course.practiceSubmit('tip')");
		// $("#footer0").text("完成答题");
		// $("#footer0").css("background-color","#5f7ec7");
		SetLS("chapter",Course.item.chapter[chapterNum]);
		Course.item.chapter[chapterNum]&&Course.item.chapter[chapterNum].knowledge&&SetLS("knowledge",Course.item.chapter[chapterNum].knowledge[knowledgeNum]);
		var knowledge= Course.item.chapter[chapterNum]&&Course.item.chapter[chapterNum].knowledge&&Course.item.chapter[chapterNum].knowledge[knowledgeNum];
		
		if (flag) {
			$("#player").html('<div class="ub-img7 imgScale" style="background-image:url(' + Core.id2url(GetLS("course")) + ');width:100%;"></div>');
			$(".imgScale").height($(".imgScale").width()*9/16+"px");
		}
		if(knowledge){
			SetLS("knowledgeId",knowledge._id);
			//知识点描述
			/*if (!flag){
				$("#player").html('<div class="imgScale c_gre" style="overflow: auto;"><p class="upp5">知识点描述 :</p><p class="uplr_p5">' + knowledge.desc + '</p></div>');
				$(".imgScale").height($(".imgScale").width()*9/16+"px");
			}*/	
			//练习
			$ajax({
				url: "/examine/detailKnowledge",
				data:{
					_id: knowledge._id
				},
				success: function(res){
					knowledge.exam = res.result;
					SetLS("examItem",knowledge);
					Course.practiceFn("exam",knowledge.exam);
					$(".score").addClass("hide");
				}
			});
			//评论
			Course.commentInit(knowledge._id);
			//教材
			Course.materialInit(knowledge.material);
			//视频
			Course.videoInit(knowledge.video);
		}
		//目录
		Course.myGuideInit(Course.item,chapterNum,knowledgeNum);

		$("#comment").css("min-height",$("body").height()-$("#player").height()-$("#tabTitle").height());
	},
	guideInit: function(course){ 
		var html = "";
		var result = course.chapter; 
		for (var i=0; i<result.length; ++i) {
			html += '<div class="ub ub-f1 ub-ver upb_p5">' + 
					'	<div class="ub-f1 c_gra ubb b_gra uptlbrp8082" ontouchstart="zy_touch()" onclick="Course.knowledgeToggle()">' + result[i].name + '</div>' + 
					'	<div class="ub ub-ver uplr_2 c_gra2 knowledgeEvt">';	
			for (var j=0; j<result[i].knowledge.length; ++j) {
				html += '<div class="ub-f1 uptlp85 ubb b_gra">' + result[i].knowledge[j].name + '</div>';
			}
			html += '</div>' + 
				'</div>';
		}
		$("#guide").html(html);
		$(".knowledgeEvt").each(function(i){ 
			if (i!=0)
				$(this).removeClass("ub").addClass("hide");	
		});
	},
	myGuideInit: function(course,chapterNum,knowledgeNum){ 
		var result = course.chapter;
		var html = "";
		for (var i=0; i<result.length; ++i) {
			var chapterjump = (result[i].category == 0?'Course.knowledgeToggle()':'Course.jumpExam(' + i + ')');
			html += '<div data-chapter="' + i + '" class="ub ub-f1 ub-ver upb_p5">' + 
					'	<div class="ub-f1 c_gra ubb b_gra uptlbrp8082" ontouchstart="zy_touch()" onclick="' + chapterjump + '">' + result[i].name + '</div>' + 
					'	<div class="ub ub-ver uplr_2 c_gra knowledgeEvt">';	
			if (!result[i].knowledge)
				result[i].knowledge = new Array();
			for (var j=0; j<result[i].knowledge.length; ++j) {
				var im_learn = (chapterNum==i&&knowledgeNum==j)?"im_icon_learning":"";
				var text_learn = "";
				if (result[i].knowledge[j].status == 3)
					text_learn = "c_input";
				else if (result[i].knowledge[j].status == 1 || result[i].knowledge[j].status == 2)
					text_learn = "c_org";
				text_learn = (chapterNum==i&&knowledgeNum==j)?"c_gre":text_learn;
				html += '<div class="ub ub-ac ub-f1 uptlp85 ubb b_gra">' + 
						'	<div class="ub-img ' + im_learn + ' uh1 uw1 upr_1 selEvt"></div>' + 
						'	<div data-knowledge="' + j + '" class="' + text_learn + ' fgEvt" onclick="Course.courseFn(' + i + ',' + j + ')">' + result[i].knowledge[j].name + '</div>' + 
						'</div>';
			}
			html += '</div>' + 
				'</div>';
		}
		$("#guide").html(html);
		$(".knowledgeEvt").each(function(i){ 
			if (i!=chapterNum)
				$(this).removeClass("ub").addClass("hide");	
		});
	},
	knowledgeToggle: function(){ 
		var $this = $(event.currentTarget);
		var knowEvt = $this.next(".knowledgeEvt");
		if (knowEvt.hasClass("hide")){
			$(".knowledgeEvt").removeClass("ub").addClass("hide");
			knowEvt.addClass("ub").removeClass("hide");
		} else { 
			$(".knowledgeEvt").removeClass("ub").addClass("hide");
		}	
	},
	materialInit: function(material){
		var html = '';
		for (var i=0; i<material.length; ++i) {
			html += '<div data-material="' + i + '" class="ub ub-f1 ub-ver upb_p5">' + 
					'	<div class="ub-f1 c_gra ubb b_gra uptlbr1p52 td-ul t-blu" ontouchstart="zy_touch()" onclick="Course.openPdf(\'' + material[i].name + '\',\'' + material[i].url + '\');">' + material[i].name + '</div>' + 
					'</div>';
		}
		$("#material").html(html);
	},
	videoInit: function(video){
		var html = '';
		for (var i=0; i<video.length; ++i) {
			html += '<div data-video="' + i + '" class="ub ub-f1 ub-ver upb_p5">' + 
					'	<div class="ub-f1 c_gra ubb b_gra uptlbr1p52 td-ul t-blu" ontouchstart="zy_touch()" onclick="Course.openVideo(\'' + video[i].url + '\');">' + video[i].name + '</div>' + 
					'</div>';
		}
		$("#video").html(html);
	},
	openPdf: function(name,url){
		window.open(Core.ATTACH_VER +url);
	},
	openMaterial: function(name,url){ 
		Download.download(Core.ATTACH_VER+url, "attach/"+name, function(status){
			if (status == 1) {
				uexDocumentReader.openDocumentReader("wgt://data/attach/"+name);
			}
		}, true);
	},
	openVideo: function(url){ 
		uexVideo.open(Core.ATTACH_VER+url, 1);
	},
	messaageInit: function(to){ 
		var data = new Object();
		data.to = to;
		data.knowledge = GetLS("knowledge")._id;

		$ajax({
			url: "/message/list",
			data: data,
			success: function(res){
				var data = res.result;
				var html = Course.gnHtml(data);
				if (data.length == 0){ 
					html = 	'<div id="defmess" class="ub ub-ver ub-f1 ub-ac ub-pc ufp9" style="margin-top:10%;">' + 
							'	<div class="uh12 uw12 ub-img7 im_mess_default"></div>' + 
							'	<div class="uf1p3 upp5 c_gra1">有问题？赶快向老师提问吧！</div>' + 
							'</div>';
				}
				$("#messList").html(html);
			}
		});
	},
	send: function() {
		var msgcontent = $("#msg").val();
		if (msgcontent == "") {
			$alert("发送内容不能为空");
			return;
		}
		if (msgcontent.length > 200) {
			$alert("字数已超过最多字数限制");
			return;
		}
		$("#msg").val("");

		var data = new Object();
		data.content = msgcontent;
		data.media = 0;
		
		var mType = GetLS("mType");
		if (!GetLS("tutor")&&mType == "message"){ 
			$alert("该课程下暂时没有老师，无法完成答疑功能");
			return;
		}
		if (mType == "message"){ 
			data.knowledge = GetLS("knowledge")._id;
			data.to = GetLS("tutor")._id;
			$ajax({
				url: "/message/add",
				data: data,
				success: function(res){
					CCall("Course.sendAppend('" + JSON.stringify(res.result) + "')");
				}
			});
		} else if (mType == "comment"){ 
			data.cid = GetLS("courseId");
			data.chid = GetLS("chapter")._id;
			data.kid = GetLS("knowledge")._id;

			$ajax({
				url: "/comment/upsert",
				data: data,
				success: function(res){
					res.result.ownerType = CurrentUser.category;
					res.result.ownerPhoto = CurrentUser.photo;
					CCall("Course.sendCommentAppend('" + JSON.stringify(res.result) + "')");
				}
			});
		}
	},
	jumpSinSend: function(){
		var msgcontent = $("#msg").val();
		if (msgcontent == "") {
			$alert("发送内容不能为空");
			return;
		}
		if (msgcontent.length > 200) {
			$alert("字数已超过最多字数限制");
			return;
		}
		$("#msg").val("");

		CCall("Course.sinSend('" + msgcontent + "');");	
	},
	sinSend: function(msgcontent){
		var data = new Object();
		data.content = msgcontent;
		data.media = 0;
		data.cid = GetLS("courseId");
		data.chid = GetLS("chapter")._id;
		data.kid = GetLS("knowledge")._id;

		$ajax({
			url: "/comment/upsert",
			data: data,
			success: function(res){
				res.result.ownerType = CurrentUser.category;
				res.result.ownerPhoto = CurrentUser.photo;
				if ($("#defmess").length > 0)
					$("#defmess").remove();
				$("#scroller-content").append(Course.gnCommentContent(new Array(res.result)));
				setTimeout(function(){Course.myScroll.refresh()}, 800);
				var singHeight = $("#scroller-content>div:eq(0)").height();
				Course.myScroll.scrollTo(0,Course.myScroll.maxScrollY-singHeight-10); 
			}
		});
	},
	sendPhoto: function() {

		Upload.init(Core.API_VER + "/upload", function(res) {

		 	if (res.code) {
		 		$alert(res.codemsg);
		 		return;
		 	}
		 	var data = new Object();
			data.media = 1;
			data.content = res.result.url;

			var mType = GetLS("mType");
			if (mType == "message"){

				data.knowledge = GetLS("knowledge")._id;
				data.to = GetLS("tutor")._id;
				$ajax({
					url: "/message/add",
					data: data,
					success: function(res) {  
						Course.sendAppend(JSON.stringify(res.result));
					}
				});
			} else if (mType == "comment"){

				data.cid = GetLS("courseId");
				data.chid = GetLS("chapter")._id;
				data.kid = GetLS("knowledge")._id;
				$ajax({
					url: "/comment/upsert",
					data: data,
					success: function(res){
						Course.sendCommentAppend(JSON.stringify(res.result));
					}
				});
			}	
		});
	},
	sendAppend: function(item) {
		$("#defmess").remove();
		item = JSON.parse(item);
		var html = Course.gnHtml(new Array(item));
		$("#messList").append(html);
	},
	sendCommentAppend: function(item){ 
		$("#defcom").remove();
		item = JSON.parse(item);
		var html = Course.gnCommentContent(new Array(item));
		$("#commentList").append(html);
		window.scrollTo(0,99999);	
	},
	gnHtml: function(items) {
		var html = "";
		for (var i = 0; i < items.length; ++i) {
			var content = "";
			if (items[i].from == CurrentUser._id) {
				if (items[i].media == 0) {
					content = '	<div class="talk_ctn" style="float:right">' +
								'      	<div class="upp5 wb_a talk_ctn right umw3 uml_2 c_gra umw12 umh_4" style="float:none;" ontouchstart="zy_touch(\'talk_ctn_act\', undefined, \'longpress\')" onclick="Appcan.copy(\''+ items[i].content +'\');">' +
								'         	<div class="uw1p5 uh1p5 ub_img im_talk_right" style="position: absolute;top: 0;right: -1em;"></div>' + 
								'			<div class="ub ub-ver">' + 
								'				<div class="ub-f1 umh_3">' + items[i].content + '</div>' + 
								'				<div class="ufp8 tx-l c_gra1 upt_p5">' + Core.offsetDate(items[i].create) + '</div>' +
								'			</div>' + 
								'     	</div>' +
								'</div>';
				} else if (items[i].media == 1) {
					content = '<div class="uw7 uh5 ub_img_cover photoBrowserEvent" data-url="'+ items[i].content +'" style="background-image:url('+ Core.id2url(items[i].content, "photo") +'); background-size:cover; float:right" ontouchstart="zy_touch()" onclick="ImageBrowser(\'' + items[i].content + '\')"></div>'+
								'<div class="ufp8 tx-r" style="clear:both">' + Core.offsetDate(items[i].create) + '</div>';
				}
				html += '<div class="ub-f1 ub uptb_1">' +
					'	 <div class="uw3"></div>' +
					'    <div class="ub-f1 upr_1">' + content +
					'    </div>' +
					'	<div class="ub ub-ac ub-ver" style="margin-top: -4%;">' + 
					'    	<div class="uw3 uh3 umar-tp5 ub_img_cover uc-ap50" style="background-image:url(\'' + Core.id2url(CurrentUser) + '\');"></div>' +
					'    	<div class="umar-tp5 uml_p5 c_gra1">' + CurrentUser.name + '</div>' +
					'	</div>' + 
					'</div>';
			} else {
				items[i].photo = items[i].fromUrl;
				items[i].category = items[i].fromType;
				if (items[i].media == 0) {
					content = 	'<div class="talk_ctn">' +
							  	'		<div class="upp5 wb_a talk_ctn left umw3 umar-r2 c_gra umw12 umh_4" style="" ontouchstart="zy_touch(\'talk_ctn_act\', undefined, \'longpress\')" onclick="Appcan.copy(\''+ items[i].content +'\');">' +
							  	'			<div class="uw1p5 uh1p5 ub_img im_talk_left" style="position: absolute;top: 0;left: -1em;"></div>' + 
							  	'			<div class="ub ub-ver">' + 
								'				<div class="ub-f1 umh_3">' + items[i].content + '</div>' + 
								'				<div class="ufp8 tx-l c_gra1 upt_p5">' + Core.offsetDate(items[i].create) + '</div>' +
								'			</div>' + 
							  	'		</div>' +
							  	'</div>';
				} else if (items[i].media == 1) {
					content = '<div class="uw7 uh5 ub_img photoBrowserEvent" data-url="'+ items[i].content +'" style="background-image:url('+ Core.id2url(items[i].content, "photo") +'); background-size:cover;" ontouchstart="zy_touch()" onclick="ImageBrowser(\'' + items[i].content + '\')"></div>'+
								'<div class="ufp8 tx-l" style="clear:both">' + Core.offsetDate(items[i].create) + '</div>';
				}
				html += '<div class="ub-f1 ub uptb_1">' +
						'	<div class="ub ub-ac ub-ver" style="margin-top: -4%;">' + 
						'    	<div class="uw3 uh3 umar-tp5 ub_img_cover uc-ap50" style="background-image:url(\'' + Core.id2url(items[i]) + '\');"></div>' +
						'    	<div class="umar-tp5 umr_p5 c_gra1">' + items[i].fromName + '</div>' +
						'	</div>' + 
						'    <div class="ub-f1 upl_1">' + content +
						'    </div>' +
						'	 <div class="uw3"></div>' +
						'</div>';
			}
		}
		return html;
	},
	selectTeacher: function(){  
		var tutors = GetLS("course").tutors;
		var titleArr = [];
		for (var i = 0; i < tutors.length; ++i)
			titleArr.push(tutors[i].name);
		ActionSheet("请选择老师", "取消", titleArr, function(data) {
			$("#teacherName").text(titleArr[data]);
			$("#teacherPhoto").css("background-image","url('" + Core.id2url(tutors[data]) + "')");
			SetLS("tutor",tutors[data]);
			//clearTimeout(messTimeOut);
			Course.messaageInit(tutors[data]._id);
			//setTimeout(Course.messaageInit(course.tutors[data]._id), 1000*2);
		});
	},
	commentInit: function(knowledgeId){ 
		$ajax({
			url: "/comment/list",
			data: {
				kid: knowledgeId
			},
			success: function(res){
				var data = res.result.results;
				var html;
				if (data.length == 0){ 
					html = 	'<div id="defcom" class="ub ub-ver ub-f1 ub-ac ub-pc" style="margin-top:10%;">' + 
							'	<div class="uh12 uw12 ub-img7 im_comment_default"></div>' + 
							'	<div class="uf1p3 upp5 c_gra1">还没有人发表评论，赶快发表您的看法吧！</div>' + 
							'</div>';
				}else {
					html = Course.gnCommentContent(data);
				}
				$("#commentList").html(html);
			}
		});
	},
	sinCommentInit: function(knowledgeId){
		$ajax({
			url: "/comment/list",
			data: {
				kid: knowledgeId,
				start: Course.commentIndex,
				count: Res.count
			},
			success: function(res){
				Course.commentIndex += Res.count;
				var data = res.result.results;
				var html;
				if (data.length == 0){ 
					/*html = 	'<div id="defcom" class="ub ub-ver ub-f1 ub-ac ub-pc" style="margin-top:10%;">' + 
							'	<div class="uh12 uw12 ub-img7 im_comment_default"></div>' + 
							'	<div class="uf1p3 upp5 c_gra1">还没有人发表评论，赶快发表您的看法吧！</div>' + 
							'</div>';*/
				}else {
					html = Course.gnCommentContent(data);
				}
				$("#scroller-content").html(html);
				Course.iscrollLoaded();
				Course.myScroll.scrollTo(0,Course.myScroll.maxScrollY); 
			}
		});
	},
	iscrollLoaded: function(){
        var myScroll,
            upIcon = $("#up-icon"),
            downIcon = $("#down-icon");
            
        myScroll = new IScroll('#wrapper', { probeType: 3, mouseWheel: true });
        
        myScroll.on("scroll",function(){
            var y = this.y,
                maxY = this.maxScrollY - y,
                downHasClass = downIcon.hasClass("reverse_icon"),
                upHasClass = upIcon.hasClass("reverse_icon");
            
            if(y >= 40){
                !downHasClass && downIcon.addClass("reverse_icon");
                return "";
            }else if(y < 40 && y > 0){
                downHasClass && downIcon.removeClass("reverse_icon");
                return "";
            }
            
            if(maxY >= 40){
                !upHasClass && upIcon.addClass("reverse_icon");
                return "";
            }else if(maxY < 40 && maxY >=0){
                upHasClass && upIcon.removeClass("reverse_icon");
                return "";
            }
        });
        
        myScroll.on("slideDown",function(){
            if(this.y > 40){
            	if (Course.flag){
            		$("#scroller-pullDown").addClass("flip").addClass("loading");
                	Course.sinCommentPrepend(this);
            	}
                upIcon.removeClass("reverse_icon")
            }
        });
        
        myScroll.on("slideUp",function(){
            if(this.maxScrollY - this.y > 40){
                //alert("slideUp");
                upIcon.removeClass("reverse_icon")
            }
        });
        Course.myScroll = myScroll;
	},
	sinCommentPrepend: function(myScroll){
		Course.flag = false;
		$ajax({
			url: "/comment/list",
			data: {
				kid: GetLS("knowledgeId"),
				start: Course.commentIndex,
				count: Res.count
			},
			success: function(res){
				if (res.result.results.length == 0){
					Course.flag = false;
					$("#scroller-pullDown").removeClass("flip").removeClass("loading");
					return $alert("没有消息了");
				} else
					Course.flag = true;
				Course.commentIndex += Res.count;
				var data = res.result.results;
				var html = Course.gnCommentContent(data);
				$("#scroller-content").prepend(html);
				setTimeout(function(){myScroll.refresh()}, 800);
				setTimeout(function(){$("#scroller-pullDown").removeClass("flip").removeClass("loading");}, 800);
				
			}
		});
	},
	gnCommentContent: function(item){
		var html = "";
		var ownerName = CurrentUser.name;
		var length = item.length;
		for (var i = length-1; i >=0; i--){
			if (item[i].ownerName)
				ownerName = item[i].ownerName;
			var owner = new Object();
			owner.category = item[i].ownerType?item[i].ownerType:Role.STUDENT;
			owner.photo = item[i].ownerPhoto;

			html += '<div data-id="' + item[i]._id + '" class="ub ub-ver ubb b_gra uptb_1" ontouchstart="zy_touch(\'\', \'Course.report\');" onclick="">' + 
					'	<div class="ub-f1 uw65 c_tab uf1p1">' + item[i].content + '</div>' + 
					'	<div class="ub">' + 
					'		<div class="uw75"></div>' + 
					'		<div class="ub ub-f1 c_gra2 ub-ver ufp8">' + 
					'			<div class="ub">'+
					'				<div class="uw2p5 uh2p5 ub-img1 uc-ap50" style="background-image:url(' + Core.id2url(owner) + ');"></div>' + 
					'				<div class="ub-f1 ub ub-ac">&nbsp;&nbsp;' + ownerName + '</div>' + 
					'			</div>'+
					'			<div class="ub ub-ac">&nbsp;' + (new Date(item[i].create)).pattern("yyyy-MM-dd") + '</div>' + 
					'		</div>' + 	
					'	</div>' + 
					'</div>';		
		}				
	    return html;            
	},
	report: function(dom){
		var id = $(dom).data("id");
		$alert(id);
	},
	jumpExam: function(i){ 
		$(".knowledgeEvt").removeClass("ub").addClass("hide");
		SetLS("chapterId",GetLS("course").chapter[i]._id);
		OpenNewWin("study_myExam");
	},
	examInit: function(){ 
		var chapterId = GetLS("chapterId");
		$ajax({
			url: "/examine/detailKnowledge",
			data:{
				_id: chapterId
			},
			success: function(res){
				SetLS("exam",res.result);
				Course.examFn("content",res.result);
			}
		});
		
	},
	practiceFn: function(htmlId,res){ 
		var SINGLE_CHOICE = '',MULTIPLE_CHOICE = '',JUDGE = '',FILL = '',SUBJECTIVE = '',LIGATURE = '',SORT = '';
		var SINGLE_NUM = 0,MULTIPLE_NUM = 0,JUDGE_NUM = 0,FILL_NUM = 0,SUBJECTIVE_NUM = 0,LIGATURE_NUM = 0,SORT_NUM = 0;
		for (var i = 0; i < res.length; i ++){
			if (res[i].QuestionType == EXAMTYPE.SINGLE_CHOICE){
				SINGLE_NUM ++;
				SINGLE_CHOICE += '<div class="cnt cntevt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>'  +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong"><span class="practiceNum"></span>、' + res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	SINGLE_CHOICE += '<li>' + 
                                    '<label><input type="radio" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i].QuestionOptionList[j].Exam_BankQuestionId + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      	
                    SINGLE_CHOICE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;">正确答案 : </h4>';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		SINGLE_CHOICE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		             SINGLE_CHOICE +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +     
		             					'<div class="issbor"></div>' + 	
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.MULTIPLE_CHOICE){
				MULTIPLE_NUM ++;
				MULTIPLE_CHOICE += '<div class="cnt cntevt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong"><span class="practiceNum"></span>、' + res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	MULTIPLE_CHOICE += '<li>' + 
                                    '<label><input type="checkbox" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i].QuestionOptionList[j].Exam_BankQuestionId + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      
                    MULTIPLE_CHOICE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 	
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;">正确答案 : </h4><div style="float:left;">';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		MULTIPLE_CHOICE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		                MULTIPLE_CHOICE +=	'</div><div class="hide tipEvt ub" style="padding:1em;clear:both;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
		                					'<div class="issbor"></div>' + 	 
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.JUDGE){
				JUDGE_NUM ++;
				JUDGE += '<div class="cnt cntevt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong"><span class="practiceNum"></span>、'+ res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	JUDGE += '<li>' + 
                                    '<label><input type="radio" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i].QuestionOptionList[j].Exam_BankQuestionId + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      
                    JUDGE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 	
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;">正确答案 : </h4>';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		JUDGE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		                JUDGE +='<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
		                		'<div class="issbor"></div>' + 	       
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.LIGATURE){
				LIGATURE_NUM ++;
				LIGATURE += '<div class="cnt cntevt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong"><span class="practiceNum"></span>、'+ res[i].Content + '</h5>' + 
                    			'<div class="matchByLineBox mlBoxCol">';
                    			var left = '<div class="matchSide matchSideQue">';
                    			var right = '<div class="matchSide matchSideAns">';
                    			for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
	                            	if (res[i].QuestionOptionList[j].OrderNum%2 == 1){
	                            		left += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '">' + res[i].QuestionOptionList[j].Content + '</div>';
	                            	}
	                            	else if (res[i].QuestionOptionList[j].OrderNum%2 == 0){
	                            		right += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '">' + res[i].QuestionOptionList[j].Content + '</div>';
	                            	}
	                            }
	                            left += '</div>';
	                            right += '</div>';
                   			LIGATURE += left + right + 
                   			'</ul>' + 
                   			'<div class="issbor"></div>';	
                   		
                        LIGATURE += '<h4 class="hide tipEvt c-wh c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;font-weight: normal;">点击下面内容查看正确答案 : </h4>' + 
                        		'<ul class="hide tipEvt c-wh" style="background-color: #FFF;font-size: 1em;">' + 
                        			'<div class="matchByLineBox mlBoxCol" style="width:75%;">';
                        			var left = '<div class="matchSide matchSideQue">';
                        			var right = '<div class="matchSide matchSideAns">';
                        			for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                            	if (res[i].QuestionOptionList[j].OrderNum%2 == 1){
		                            		for (var l = 0; l < res[i].QuestionOptionList.length; l ++){
		                            			if (res[i].QuestionOptionList[l].OrderNum == res[i].QuestionOptionList[j].OrderNum+1)
		                            				var ans = res[i].QuestionOptionList[l].Id;
		                            		}
		                            		left += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '0" ans="' + ans + '0">' + res[i].QuestionOptionList[j].Content + '</div>';
		                            	}
		                            	else if (res[i].QuestionOptionList[j].OrderNum%2 == 0){
		                            		right += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '0">' + res[i].QuestionOptionList[j].Content + '</div>';
		                            	}
		                            }
		                            left += '</div>';
		                            right += '</div>';
                       			LIGATURE += left + right + 
                       			'</ul>';   
                       	LIGATURE +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
                       				'<div class="issbor"></div></div>'; 
                        		   
			}
			else if (res[i].QuestionType == EXAMTYPE.SORT){
				SORT_NUM ++;
				//冒泡排序,用于正确答案
				var temp = 0;
				var targetArr = res[i].QuestionOptionList;
	            for(var k = 0;k<targetArr.length;k++){
	                for(var j = k;j<targetArr.length;j++){
	                    if(targetArr[k].OrderNum>targetArr[j].OrderNum){
	                        temp = targetArr[k];
	                        targetArr[k] = targetArr[j];
	                        targetArr[j] = temp;
	                     }
	                 }
	            }
				SORT += '<div class="cnt cntevt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<h5 style="margin: 1em 0em 1em 7.5%;position:relative;"><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong"><span class="practiceNum"></span>、'+ res[i].Content + '</h5>' + 
                            '<div class="custom_order" id="custom_order">' + 
		                    '    <div class="custom_sort_form">' + 
		                    '        <ul class="sort_div" id="sort_div" style="padding:1em;">';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	SORT += '<li class="ub" id="' + res[i].QuestionOptionList[j].Id + '" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" class="drag_li" style="left: 0px; top: 0px;">' + 
                                '    <div class="v_middle ub-f1" id="' + res[i].QuestionOptionList[j].Id + '_h" style="cursor: move;">' + res[i].QuestionOptionList[j].Content + '</div>' + 
                                '	<div class="upp5 ub ub-ac" ontouchstart="zy_touch" onclick="Course.topMove()">上移</div>' + 
                                '	<div class="upp5 ub ub-ac" ontouchstart="zy_touch" onclick="Course.bottomMove()">下移</div>' + 
                                '</li>';
                    }      
	                    SORT += '	 </ul>' + 
	                    		'<div class="issbor"></div>' + 	
			                    '<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;">正确答案 : </h4>';
			                		for (var j = 0; j < targetArr.length; j ++){
			                        	SORT += '<li class="hide tipEvt" id="' + targetArr[j].Id + '" data-ordernum="' + targetArr[j].OrderNum + '" class="drag_li" style="left: 0px; top: 0px;width:70%;margin:0.5em auto;background-color: #FFF;">' + 
				                                '    <div class="v_middle" id="' + targetArr[j].Id + '_h" style="cursor: move;">' + targetArr[j].Content + '</div>' + 
				                                '</li>';
		                        	}
	                    	SORT +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
	                    			'<div class="issbor"></div>' + 	
		                        '</div>' + 
		                    '</div>' + 
		                '</div>';            
			}
		}

		var html = SINGLE_CHOICE + MULTIPLE_CHOICE + JUDGE + FILL + SUBJECTIVE + LIGATURE + SORT;
		if (res.length)
			html = '<h3 id="quesType"></h3>' + html;
		$("#" + htmlId).html(html);
		$("#quesType").text(EXAMTYPE_LABEL[$(".issue .cnt:first").data("questiontype")]);
		$(".practiceNum").text(Course.practiceNum);
		$(".issue .cnt:first").addClass("selected");
		$(".tipEvt,.scoview").removeClass("ub");
		if (GetLS("examItem").category == 2)
			$(".scoview").addClass("ub");
		$(".issue input").click(function(){ 
			$(this).parents("ul").find("input").each(function(i){ 
				if ($(this).prop("checked"))
					$(this).parents("li").css("background-color"," #ddebf9");
				else
					$(this).parents("li").css("background-color"," #f5f5f5");
			})	
		});;	
		// 初始化连线canvas
		var mblBoxs=$(".matchByLineBox");
		mblArr=[];//全局 存储所有mbl实例
		mblBoxs.each(function(x){
			var mbl=new MatchByLine(mblBoxs.eq(x));
			mbl.init();
			mblArr.push(mbl);
		});
		// 初始化拖动排序
		initDrag();
	},
	practiceSubmit: function(flag){ 
		if (!CurrentUser)
			return $alert("您没有答题权限");
		var knowledgeEvtge = GetLS("knowledge");
		if ($(".cnt").length == 0)
			return $alert("还未有题目，耐心等待吧");
		var data = new Object();
		data.isLabour = false;
		data.questions = new Array();
		data.errSet = new Array();
		var score = 0;

		$(".issue").find(".cnt").each(function(i){
			$(this).data("nullQues","false");
			data.questions[i] = new Object();
			if (flag == "1")
				data.questions[i] = knowledge.exam[$(this).data("num")];
			else
				data.questions[i] = GetLS("examItem").exam[$(this).data("num")];
			data.questions[i].trueOrFalse = false;
			data.questions[i].cid = GetLS("courseId");
			var QuestionType = $(this).data("questiontype");
			$(this).data("torf","false");
			if (QuestionType == EXAMTYPE.SINGLE_CHOICE){
				data.questions[i].stuAnswer = new Array();
				data.questions[i].stuAnswer[0] = $(this).find("input[type='radio']:checked").attr("id");
				if ($(this).find("input[type='radio']:checked").data("ifrightanswer")){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					$(this).data("torf","true");
				} else
					data.errSet.push(data.questions[i]);	
				if ($(this).find("input[type='radio']:checked").length == 0){
					$(this).data("nullQues","true");
				}	
			}
			else if (QuestionType == EXAMTYPE.MULTIPLE_CHOICE){
				data.questions[i].stuAnswer = new Array();
				var flag = false;
				$(this).find("input[type='checkbox']").each(function(j){
					if ($(this).data("ifrightanswer") && $(this).prop("checked")){
						flag = true;
					} else if (($(this).data("ifrightanswer") && !$(this).prop("checked"))|| (!$(this).data("ifrightanswer") && $(this).prop("checked"))){
						flag = false;
						return false;
					}
				});
				$(this).find("input[type='checkbox']:checked").each(function(j){
					data.questions[i].stuAnswer[j] = $(this).attr("id");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					$(this).data("torf","true");
				} else 
					data.errSet.push(data.questions[i]);
				if ($(this).find("input[type='checkbox']:checked").length == 0){
					$(this).data("nullQues","true");
				}	
			}
			else if (QuestionType == EXAMTYPE.JUDGE){
				data.questions[i].stuAnswer = new Array();
				data.questions[i].stuAnswer[0] = $(this).find("input[type='radio']:checked").attr("id");
				if ($(this).find("input[type='radio']:checked").data("ifrightanswer")){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					$(this).data("torf","true");
				} else 
					data.errSet.push(data.questions[i]);
				if ($(this).find("input[type='radio']:checked").length == 0){
					$(this).data("nullQues","true");
				}	
			}
			else if (QuestionType == EXAMTYPE.LIGATURE){
				var $evt = $(this);
				var flag = false;
				var nullFlag = false;
				$(this).find(".matchSideQue .matchOne").each(function(j){
					if ($(this).data("ordernum") == ($("#" + $(this).attr("ans")).data("ordernum") - 1)){
						flag = true;
					}else{
						flag = false;
						return false;
					}
				});
				data.questions[i].stuAnswer = new Array();
				$(this).children("ul:first").find(".matchSideQue .matchOne").each(function(j){
					if ($(this).attr("ans"))
						nullFlag = true;
					data.questions[i].stuAnswer[2*j] = $(this).attr("id");
					data.questions[i].stuAnswer[2*j + 1] = $(this).attr("ans");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					$(this).data("torf","true");
				} else 
					data.errSet.push(data.questions[i]);
				if (!nullFlag)
					$(this).data("nullQues","true");
			}
			else if (QuestionType == EXAMTYPE.SORT){
				var $evt = $(this);
				var flag = false;
				$(this).find(".custom_sort_form li").each(function(j){
					if ($(this).next("li").length != 0){
						if ($(this).data("ordernum") == ($(this).next("li").data("ordernum") - 1)){
							flag = true;
						}else{
							flag = false;
							return false;
						}
					}	
				});
				data.questions[i].stuAnswer = new Array();
				$(this).find(".custom_sort_form li").each(function(j){
					data.questions[i].stuAnswer[j] = $(this).attr("id");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;

				} else 
					data.errSet.push(data.questions[i]);
			}
		});

		var $selEvt = $(".issue .cnt.selected");
		if ($selEvt.data("nullQues") == "true"){
			$alert("题目还没有完成，继续完成它吧!");	
			return;
		}
		if (flag == "tip"){
			$(".issue").find(".right,.wrong").css("display","none");
			if ($selEvt.data("torf") == "true")
				$selEvt.find(".right").css("display","block");
			else
				$selEvt.find(".wrong").css("display","block");
			$selEvt.find(".tipEvt").removeClass("hide").addClass("ub");
			if ($selEvt.next(".cnt").length)
				$("#footer0").attr("onclick","Course.practiceSubmit('next');").text("下一题");
			else{
				$("#footer0").attr("onclick","").removeClass("bc_green").addClass("bg_gray").text("已经是最后一题");
				Course.practiceNum = 1;
				var studyData = {};
				studyData.courseId = GetLS("courseId");
				studyData.chapterId = GetLS("chapter")._id;
				studyData.knowledgeId = GetLS("knowledge")._id;
				$ajax({
					url:"/user/study",
					data:studyData,
					success: function(res){}
				});
			}
		} else { 
			if($selEvt.next(".cnt").length)
				$("#quesType").text(EXAMTYPE_LABEL[$selEvt.next(".cnt").data("questiontype")]);
			$(".issue .cnt").removeClass("selected");
			Course.practiceNum ++;
			$(".practiceNum").text(Course.practiceNum);
			$selEvt.next(".cnt").addClass("selected");
			$("#footer0").attr("onclick","Course.practiceSubmit('tip');").text("提交");
		}	
	},
	examFn: function(htmlId,res){ 
		var SINGLE_CHOICE = '',MULTIPLE_CHOICE = '',JUDGE = '',FILL = '',SUBJECTIVE = '',LIGATURE = '',SORT = '';
		var SINGLE_NUM = 0,MULTIPLE_NUM = 0,JUDGE_NUM = 0,FILL_NUM = 0,SUBJECTIVE_NUM = 0,LIGATURE_NUM = 0,SORT_NUM = 0;
		for (var i = 0; i < res.length; i ++){
			if (res[i].QuestionType == EXAMTYPE.SINGLE_CHOICE){
				SINGLE_NUM ++;
				SINGLE_CHOICE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>'  +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + SINGLE_NUM + "、" + res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	SINGLE_CHOICE += '<li>' + 
                                    '<label><input type="radio" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i]._id + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      		
                    SINGLE_CHOICE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;"><img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>正确答案 : </span></h4>';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		SINGLE_CHOICE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		             SINGLE_CHOICE +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +     
		             					'<div class="issbor"></div>' + 	
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.MULTIPLE_CHOICE){
				MULTIPLE_NUM ++;
				MULTIPLE_CHOICE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + MULTIPLE_NUM + "、"  + res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	MULTIPLE_CHOICE += '<li>' + 
                                    '<label><input type="checkbox" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i]._id + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      
                    MULTIPLE_CHOICE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 	
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;"><img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>正确答案 : </span></h4><div style="float:left;">';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		MULTIPLE_CHOICE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		                MULTIPLE_CHOICE +=	'</div><div class="hide tipEvt ub" style="padding:1em;clear:both;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
		                					'<div class="issbor"></div>' + 	 
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.JUDGE){
				JUDGE_NUM ++;
				JUDGE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + JUDGE_NUM + "、" + res[i].Content + '</h5>';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	JUDGE += '<li>' + 
                                    '<label><input type="radio" class="uw2 uh2" data-ifrightanswer="' + res[i].QuestionOptionList[j].IfRightAnswer + '" name="' + res[i]._id + '" id="' + res[i].QuestionOptionList[j].Id + '"><font>' + res[i].QuestionOptionList[j].Content + '</font></label>' + 
                                '</li>';
                    }      
                    JUDGE +=  '</ul>' + 
                    		'<div class="issbor"></div>' + 	
                    		'<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;float: left;"<img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>正确答案 : </span></h4>';
                        		for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                        	if (res[i].QuestionOptionList[j].IfRightAnswer == "true"||res[i].QuestionOptionList[j].IfRightAnswer == true){
		                        		JUDGE += '<p class=" hide tipEvt uf1p4" style="margin:0.5em;background-color: #FFF;">' + res[i].QuestionOptionList[j].Content + '</p>';
		                        	}          		
		                        }
		                JUDGE +='<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
		                		'<div class="issbor"></div>' + 	       
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.FILL){
				FILL_NUM ++;
				FILL += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div>' + FILL_NUM + "、" + res[i].Content + '</h5>' + 
                    			'<label><input class="uba uw90 uh2 ump50 uf1p1 upp3" type="text" id="' + res[i]._id + '"></label>';
                    			for ( var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    				FILL += '<input type="hidden" id="' + res[i].QuestionOptionList[j].Id + '" value="' + res[i].QuestionOptionList[j].Content + '">';
                    			}
                   	FILL += '</ul>' + 
                   			'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
                   			'<div class="issbor"></div>' + 	
                        '</div>';      
			}
			else if (res[i].QuestionType == EXAMTYPE.SUBJECTIVE){
				SUBJECTIVE_NUM ++;
				SUBJECTIVE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div>' + SUBJECTIVE_NUM + "、" + res[i].Content + '</h5>' + 
                    			'<label><textarea class="uf1p1 upp3 uw90" id="' + res[i]._id + '"></textarea></label>';
                    			for ( var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    				SUBJECTIVE += '<input type="hidden" id="' + res[i].QuestionOptionList[j].Id + '" value="' + res[i].QuestionOptionList[j].Content + '">';
                    			}
                   	SUBJECTIVE += '</ul>' + 
                   			'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
                   			'<div class="issbor"></div>' + 	
                        '</div>';       
			}
			else if (res[i].QuestionType == EXAMTYPE.LIGATURE){
				LIGATURE_NUM ++;
				LIGATURE += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<ul>' + 
                                '<h5><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + LIGATURE_NUM + "、" + res[i].Content + '</h5>' + 
                    			'<div class="matchByLineBox mlBoxCol">';
                    			var left = '<div class="matchSide matchSideQue">';
                    			var right = '<div class="matchSide matchSideAns">';
                    			for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
	                            	if (res[i].QuestionOptionList[j].OrderNum%2 == 1){
	                            		left += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '">' + res[i].QuestionOptionList[j].Content + '</div>';
	                            	}
	                            	else if (res[i].QuestionOptionList[j].OrderNum%2 == 0){
	                            		right += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '">' + res[i].QuestionOptionList[j].Content + '</div>';
	                            	}
	                            }
	                            left += '</div>';
	                            right += '</div>';
                   			LIGATURE += left + right + 
                   			'</ul>' + 
                   			'<div class="issbor"></div>' + 	
                   		'</div>'; 
                        LIGATURE += '<h4 class="hide tipEvt c-wh c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;font-weight: normal;"><img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>点击下面内容查看正确答案 : </span></h4>' + 
                        		'<ul class="hide tipEvt c-wh" style="background-color: #FFF;font-size: 1em;">' + 
                        			'<div class="matchByLineBox mlBoxCol" style="width:75%;">';
                        			var left = '<div class="matchSide matchSideQue">';
                        			var right = '<div class="matchSide matchSideAns">';
                        			for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
		                            	if (res[i].QuestionOptionList[j].OrderNum%2 == 1){
		                            		for (var l = 0; l < res[i].QuestionOptionList.length; l ++){
		                            			if (res[i].QuestionOptionList[l].OrderNum == res[i].QuestionOptionList[j].OrderNum+1)
		                            				var ans = res[i].QuestionOptionList[l].Id;
		                            		}
		                            		left += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '0" ans="' + ans + '0">' + res[i].QuestionOptionList[j].Content + '</div>';
		                            	}
		                            	else if (res[i].QuestionOptionList[j].OrderNum%2 == 0){
		                            		right += '<div class="matchOne" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" id="' + res[i].QuestionOptionList[j].Id + '0">' + res[i].QuestionOptionList[j].Content + '</div>';
		                            	}
		                            }
		                            left += '</div>';
		                            right += '</div>';
                       			LIGATURE += left + right + 
                       			'</ul>';   
                       	LIGATURE +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
                       				'<div class="issbor"></div>'; 
                        		   
			}
			else if (res[i].QuestionType == EXAMTYPE.SORT){
				SORT_NUM ++;
				//冒泡排序,用于正确答案
				var temp = 0;
				var targetArr = res[i].QuestionOptionList;
	            for(var k = 0;k<targetArr.length;k++){
	                for(var j = k;j<targetArr.length;j++){
	                    if(targetArr[k].OrderNum>targetArr[j].OrderNum){
	                        temp = targetArr[k];
	                        targetArr[k] = targetArr[j];
	                        targetArr[j] = temp;
	                     }
	                 }
	            }
				SORT += '<div class="cnt" data-num="' + i + '" data-questiontype="' + res[i].QuestionType + '" data-id="' + res[i]._id + '">' + 
                            '<h3>' +  res[i].QtypeString + '<span class="score" data-score="' + res[i].QScore + '">' + res[i].QScore + '分</span></h3>' + 
                            '<h5 style="margin: 1em 0em 1em 7.5%;position:relative;"><div class="scoview hide ub ub-ac ub-pc">' + res[i].QScore + '分</div><img src="img/ico_right.png" class="ico_wrimg right"><img src="img/ico_err.png" class="ico_wrimg wrong">' + SORT_NUM + "、" + res[i].Content + '</h5>' + 
                            '<div class="custom_order" id="custom_order">' + 
		                    '    <div class="custom_sort_form">' + 
		                    '        <ul class="sort_div" id="sort_div" style="padding:1em;">';
                    for (var j = 0; j < res[i].QuestionOptionList.length; j ++){
                    	SORT += '<li class="ub" id="' + res[i].QuestionOptionList[j].Id + '" data-ordernum="' + res[i].QuestionOptionList[j].OrderNum + '" class="drag_li" style="left: 0px; top: 0px;">' + 
                                '    <div class="v_middle ub-f1" id="' + res[i].QuestionOptionList[j].Id + '_h" style="cursor: move;">' + res[i].QuestionOptionList[j].Content + '</div>' + 
                                '	<div class="upp5 ub ub-ac" ontouchstart="zy_touch" onclick="Course.topMove()">上移</div>' + 
                                '	<div class="upp5 ub ub-ac" ontouchstart="zy_touch" onclick="Course.bottomMove()">下移</div>' + 
                                '</li>';
                    }      
	                    SORT += '	 </ul>' + 
	                    		'<div class="issbor"></div>' + 	
			                    '<h4 class="hide tipEvt c_red" style="padding-left:1em;background-color: #FFF;margin:0.5em;"><img src="img/ico_right.png" class="fleft hide eright"><img src="img/ico_err.png" class="fleft hide ewrong"><span>正确答案 : </span></h4>';
			                		for (var j = 0; j < targetArr.length; j ++){
			                        	SORT += '<li class="hide tipEvt" id="' + targetArr[j].Id + '" data-ordernum="' + targetArr[j].OrderNum + '" class="drag_li" style="left: 0px; top: 0px;width:70%;margin:0.5em auto;background-color: #FFF;">' + 
				                                '    <div class="v_middle" id="' + targetArr[j].Id + '_h" style="cursor: move;">' + targetArr[j].Content + '</div>' + 
				                                '</li>';
		                        	}
	                    	SORT +=	'<div class="hide tipEvt ub" style="padding:1em;"><div class="c_red upr_p5" style="background-color:#f5f5f5;">解析 : </div><div class="ub-f1" style="background-color:#f5f5f5;">' + (res[i].Tip) + '</div></div>' +   
	                    			'<div class="issbor"></div>' + 	
		                        '</div>' + 
		                    '</div>' + 
		                '</div>';            
			}
		}
		var num = 0;
		SINGLE_CHOICE = SINGLE_NUM>0?('<h3>' + Course.num[num] + '单选题</h3>' + SINGLE_CHOICE):"";num = SINGLE_NUM>0?num+1:num;
		MULTIPLE_CHOICE = MULTIPLE_NUM>0?'<h3>' + Course.num[num] + '多选题</h3>' + MULTIPLE_CHOICE:"";num = MULTIPLE_NUM>0?num+1:num;
		JUDGE = JUDGE_NUM>0?'<h3>' + Course.num[num] + '判断题</h3>' + JUDGE:"";num = JUDGE_NUM>0?num+1:num;
		FILL = FILL_NUM>0?'<h3>' + Course.num[num] + '填空题</h3>' + FILL:"";num = FILL_NUM>0?num+1:num;
		SUBJECTIVE = SUBJECTIVE_NUM>0?'<h3>' + Course.num[num] + '问答题</h3>' + SUBJECTIVE:"";num = SUBJECTIVE_NUM>0?num+1:num;
		LIGATURE = LIGATURE_NUM>0?'<h3>' + Course.num[num] + '匹配题</h3>' + LIGATURE:"";num = LIGATURE_NUM>0?num+1:num;
		SORT = SORT_NUM>0?'<h3>' + Course.num[num] + '排序题</h3>' + SORT:"";

		var html = SINGLE_CHOICE + MULTIPLE_CHOICE + JUDGE + FILL + SUBJECTIVE + LIGATURE + SORT;
		$("#" + htmlId).html(html);
		$(".tipEvt,.scoview").removeClass("ub");
		if (GetLS("examItem").category == 2)
			$(".scoview").addClass("ub");
		$(".issue input").click(function(){ 
			$(this).parents("ul").find("input").each(function(i){ 
				if ($(this).prop("checked"))
					$(this).parents("li").css("background-color"," #ddebf9");
				else
					$(this).parents("li").css("background-color"," #f5f5f5");
			})	
		});;	
		// 初始化连线canvas
		var mblBoxs=$(".matchByLineBox");
		mblArr=[];//全局 存储所有mbl实例
		mblBoxs.each(function(x){
			var mbl=new MatchByLine(mblBoxs.eq(x));
			mbl.init();
			mblArr.push(mbl);
		});
		// 初始化拖动排序
		initDrag();
	},
	topMove: function(){ 
		var $this = $(event.currentTarget);
		var thisHtml = $this.parent().prop('outerHTML');
		var prevHtml = $this.parent().prev().prop('outerHTML');
		if (prevHtml){ 
			$this.parent().prev().before(thisHtml);
			$this.parent().remove();
		} else 
			$alert("向上移不动啦");
	},
	bottomMove: function(){ 
		var $this = $(event.currentTarget);
		var thisHtml = $this.parent().prop('outerHTML');
		var nextHtml = $this.parent().next().prop('outerHTML');
		if (nextHtml){ 
			$this.parent().next().after(thisHtml);
			$this.parent().remove();
		} else 
			$alert("向下移不动啦");
	},
	examSubmit: function(flag){ 
		if (!CurrentUser)
			return $alert("您没有答题权限");
		//flag为TRUE 结业考试    false为 每课一练
		if ($(".cnt").length == 0)
			return $alert("还未有题目，耐心等待吧");
		var data = new Object();
		data.isLabour = false;
		data.questions = new Array();
		data.errSet = new Array();
		var score = 0;
		var nullQuesNum = '';
		var trueNum = 0;
		$(".issue").find(".cnt").each(function(i){
			data.questions[i] = new Object();
			data.questions[i] = GetLS("exam")[$(this).data("num")];
			data.questions[i].trueOrFalse = false;
			data.questions[i].cid = GetLS("courseId");
			var QuestionType = $(this).data("questiontype");
			if (QuestionType == EXAMTYPE.SINGLE_CHOICE){
				data.questions[i].stuAnswer = new Array();
				data.questions[i].stuAnswer[0] = $(this).find("input[type='radio']:checked").attr("id");
				if ($(this).find("input[type='radio']:checked").data("ifrightanswer")){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else
					data.errSet.push(data.questions[i]);	
				if ($(this).find("input[type='radio']:checked").length == 0){
					nullQuesNum += ($(this).data("num")+1) + ",";
				}	
			}
			else if (QuestionType == EXAMTYPE.MULTIPLE_CHOICE){
				data.questions[i].stuAnswer = new Array();
				var flag = false;
				$(this).find("input[type='checkbox']").each(function(j){
					if ($(this).data("ifrightanswer") && $(this).prop("checked")){
						flag = true;
					} else if (($(this).data("ifrightanswer") && !$(this).prop("checked"))|| (!$(this).data("ifrightanswer") && $(this).prop("checked"))){
						flag = false;
						return false;
					}
				});
				$(this).find("input[type='checkbox']:checked").each(function(j){
					data.questions[i].stuAnswer[j] = $(this).attr("id");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else 
					data.errSet.push(data.questions[i]);
				if ($(this).find("input[type='checkbox']:checked").length == 0){
					nullQuesNum += ($(this).data("num")+1) + ",";
				}	
			}
			else if (QuestionType == EXAMTYPE.JUDGE){
				data.questions[i].stuAnswer = new Array();
				data.questions[i].stuAnswer[0] = $(this).find("input[type='radio']:checked").attr("id");
				if ($(this).find("input[type='radio']:checked").data("ifrightanswer")){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else 
					data.errSet.push(data.questions[i]);
				if ($(this).find("input[type='radio']:checked").length == 0){
					nullQuesNum += ($(this).data("num")+1) + ",";
				}	
			}
			else if (QuestionType == EXAMTYPE.LIGATURE){
				var $evt = $(this);
				var flag = false;
				var nullFlag = false;
				$(this).find(".matchSideQue .matchOne").each(function(j){
					if ($(this).data("ordernum") == ($("#" + $(this).attr("ans")).data("ordernum") - 1)){
						flag = true;
					}else{
						flag = false;
						return false;
					}
				});
				data.questions[i].stuAnswer = new Array();
				$(this).find(".matchSideQue .matchOne").each(function(j){
					if ($(this).attr("ans"))
						nullFlag = true;
					data.questions[i].stuAnswer[2*j] = $(this).attr("id");
					data.questions[i].stuAnswer[2*j + 1] = $(this).attr("ans");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else 
					data.errSet.push(data.questions[i]);
				if (!nullFlag)
					nullQuesNum += ($(this).data("num")+1) + ",";
			}
			else if (QuestionType == EXAMTYPE.SORT){
				var $evt = $(this);
				var flag = false;
				$(this).find(".custom_sort_form .sort_div>li").each(function(j){
					if ($(this).next("li").length != 0){
						if ($(this).data("ordernum") == ($(this).next("li").data("ordernum") - 1)){
							flag = true;
						}else{
							flag = false;
							return false;
						}
					}	
				});
				data.questions[i].stuAnswer = new Array();
				$(this).find(".custom_sort_form .sort_div>li").each(function(j){
					data.questions[i].stuAnswer[j] = $(this).attr("id");
				});
				if (flag){
					score += data.questions[i].QScore;
					data.questions[i].trueOrFalse = true;
					trueNum++;
				} else 
					data.errSet.push(data.questions[i]);
			}
		});
		if (nullQuesNum){
			$alert("您还有题目没有完成，继续完成它吧!");	
			return;
		}
		var allNum = $(".issue").find(".cnt").length;
		data.score = Math.round(trueNum/allNum*100);
		data.cid = GetLS("courseId");
		console.log(data);
		$ajax({
			url:"/examine/upsertPaper",
			data:data,
			success:function(res) {
				//$("#leftBtn").attr("onclick","WinClose");
				PCall("study_myExam",'$alert(\'提交后请到记录里查看成绩\');$("#footer").remove();$("#leftBtn").attr("onclick","WinClose()");');
				//PCall("study_myExam",'$("#footer").remove()')	
			}
		});
	},
	conclose: function(){ 
		return $alert("是否终止本次练习?",function(){WinClose();});
	}
}